package cn.edu.hatu.bookshop.dao;

import cn.edu.hatu.bookshop.entity.Book;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;


import java.util.List;

/**
 * @author zhangye
 */
@Repository
@Mapper

public interface BookMapper {
    @Select("select * from book")
    List<Book> listBooks();
    @Select("select * from book where classifyId = #{classifyId}")
    List<Book> getBooksByClassifyId(@Param("classifyId")int classifyId);
    @Select("select count(*) from book")
    int getTableCount();
    @Select("select * from book where bookId = #{bookId}")
    Book findById(@Param ("bookId")int bookId);
    @Select("select * from book where bookname = #{bookName}")
    Book findByName(@Param("bookName")String bookName);
    @Insert("insert into book(pubs,bookname,bookauthor,classifyId,bookcount,price,bookshelf) " +
            "values(#{book.pubs},#{book.bookName},#{book.bookAuthor},#{book.classifyId},#{book.bookCount},#{book.price},#{book.bookShelf})")
    void addBook(@Param("book") Book book);
    @Delete("delete from book where bookId = #{bookId}")
    void delBookById(@Param("bookId") int bookId);
    @Delete("delete from book where bookname = #{bookName}")
    void delBookByName(@Param("bookName")String bookName);
    @Update("update book set pubs=#{book.pubs},bookname=#{book.bookName},bookauthor=#{book.bookAuthor},classifyId=#{book.classifyId},bookcount=#{book.bookCount},price=#{book.price},bookshelf=#{book.bookShelf} where bookId=#{book.bookId}")
    void updateBook(@Param("book") Book book);
    @Select("select * from book where bookname like #{regex}")
    List<Book> fuzzyQuery(@Param("regex")String regex);

}
